package com.baizhi.cmfzmanager.service.impl;

import com.baizhi.cmfzmanager.dao.BannerDao;
import com.baizhi.cmfzmanager.entity.Banner;
import com.baizhi.cmfzmanager.service.BannerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerDao bannerDao;
    @Override
    public Map getBanners(int page, int rows) {

        int start = (page-1)*rows;
        IPage<Banner> iPage = new Page<>(start,rows);
        IPage<Banner> bannerIPage = bannerDao.selectPage(iPage, null);
        Map map = new HashMap();
        map.put("total",bannerIPage.getTotal());
        map.put("rows",bannerIPage.getRecords());
        return map;
    }

    @Override
    public void updateBanner(Banner banner) {
        bannerDao.updateBanner(banner);
    }

    @Override
    public void addBanner(Banner banner) {
        bannerDao.addBanner(banner);
    }

    @Override
    public void deleteBanner(int[] id) {
        bannerDao.deleteBanner(id);
    }

    @Override
    public List<Banner> getShowBanner() {
        return bannerDao.getShowBanner();
    }
}
